{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 7.6 \u5b9a\u4e49\u533f\u540d\u6216\u5185\u8054\u51fd\u6570\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u60f3\u4e3a sort() \u64cd\u4f5c\u521b\u5efa\u4e00\u4e2a\u5f88\u77ed\u7684\u56de\u8c03\u51fd\u6570\uff0c\u4f46\u53c8\u4e0d\u60f3\u7528 def \u53bb\u5199\u4e00\u4e2a\u5355\u884c\u51fd\u6570\uff0c\n\u800c\u662f\u5e0c\u671b\u901a\u8fc7\u67d0\u4e2a\u5feb\u6377\u65b9\u5f0f\u4ee5\u5185\u8054\u65b9\u5f0f\u6765\u521b\u5efa\u8fd9\u4e2a\u51fd\u6570\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5f53\u4e00\u4e9b\u51fd\u6570\u5f88\u7b80\u5355\uff0c\u4ec5\u4ec5\u53ea\u662f\u8ba1\u7b97\u4e00\u4e2a\u8868\u8fbe\u5f0f\u7684\u503c\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u6765\u4ee3\u66ff\u4e86\u3002\u6bd4\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "add = lambda x, y: x + y\nadd(2,3)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "add('hello', 'world')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8fd9\u91cc\u4f7f\u7528\u7684lambda\u8868\u8fbe\u5f0f\u8ddf\u4e0b\u9762\u7684\u6548\u679c\u662f\u4e00\u6837\u7684\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "def add(x, y):\n    return x + y\nadd(2,3)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "lambda\u8868\u8fbe\u5f0f\u5178\u578b\u7684\u4f7f\u7528\u573a\u666f\u662f\u6392\u5e8f\u6216\u6570\u636ereduce\u7b49\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "names = ['David Beazley', 'Brian Jones',\n        'Raymond Hettinger', 'Ned Batchelder']\nsorted(names, key=lambda name: name.split()[-1].lower())"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5c3d\u7ba1lambda\u8868\u8fbe\u5f0f\u5141\u8bb8\u4f60\u5b9a\u4e49\u7b80\u5355\u51fd\u6570\uff0c\u4f46\u662f\u5b83\u7684\u4f7f\u7528\u662f\u6709\u9650\u5236\u7684\u3002\n\u4f60\u53ea\u80fd\u6307\u5b9a\u5355\u4e2a\u8868\u8fbe\u5f0f\uff0c\u5b83\u7684\u503c\u5c31\u662f\u6700\u540e\u7684\u8fd4\u56de\u503c\u3002\u4e5f\u5c31\u662f\u8bf4\u4e0d\u80fd\u5305\u542b\u5176\u4ed6\u7684\u8bed\u8a00\u7279\u6027\u4e86\uff0c\n\u5305\u62ec\u591a\u4e2a\u8bed\u53e5\u3001\u6761\u4ef6\u8868\u8fbe\u5f0f\u3001\u8fed\u4ee3\u4ee5\u53ca\u5f02\u5e38\u5904\u7406\u7b49\u7b49\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u53ef\u4ee5\u4e0d\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u5c31\u80fd\u7f16\u5199\u5927\u90e8\u5206python\u4ee3\u7801\u3002\n\u4f46\u662f\uff0c\u5f53\u6709\u4eba\u7f16\u5199\u5927\u91cf\u8ba1\u7b97\u8868\u8fbe\u5f0f\u503c\u7684\u77ed\u5c0f\u51fd\u6570\u6216\u8005\u9700\u8981\u7528\u6237\u63d0\u4f9b\u56de\u8c03\u51fd\u6570\u7684\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\n\u4f60\u5c31\u4f1a\u770b\u5230lambda\u8868\u8fbe\u5f0f\u7684\u8eab\u5f71\u4e86\u3002"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}